package com.zjeav.lingjiao.base.baseBean;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.dalimao.corelibrary.view.LoadProgressDialog;
import com.zjeav.lingjiao.R;
import com.zjeav.lingjiao.base.utils.NetBroadcastReceiver;
import com.zjeav.lingjiao.base.utils.NetUtil;


/**
 * Created by li on 2017/6/20.
 */
public class BaseFragment extends LazyLoadFragment implements NetBroadcastReceiver.NetEvevt {
    public static NetBroadcastReceiver.NetEvevt evevt;

    /**
     * 网络类型
     */
    private int netMobile;
    public LoadProgressDialog loadProgressDialog; //加载框

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        evevt = this;
        loadProgressDialog = new LoadProgressDialog(getActivity(), R.style.MyDialog);
        inspectNet();
    }

    /**
     * 初始化时判断有没有网络
     */

    public boolean inspectNet() {
        this.netMobile = NetUtil.getNetWorkState(getActivity());

        return isNetConnect();
    }

    /**
     * 网络变化之后的类型
     */
    @Override
    public void onNetChange(int netMobile) {
        // TODO Auto-generated method stub
        this.netMobile = netMobile;
        isNetConnect();

    }

    /**
     * 判断有无网络 。
     *
     * @return true 有网, false 没有网络.
     */
    public boolean isNetConnect() {
        if (netMobile == NetUtil.NETWORK_WIFI) {
            return true;
        } else if (netMobile == NetUtil.NETWORK_MOBILE) {
            return true;
        } else if (netMobile == NetUtil.NETWORK_NONE) {
            return false;

        }
        return false;
    }


}
